package com.adopapa.ethexplorer.contoller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.protocol.core.methods.response.admin.AdminNodeInfo.NodeInfo;
import org.web3j.protocol.core.methods.response.admin.AdminPeers.Peer;

import com.adopapa.ethexplorer.service.ChaindataService;

import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/api/v1/node")
public class NodeInfoController extends BaseController {

	@Autowired
	private ChaindataService chaindataService;

	@GetMapping(path = "/nodeinfo", produces = MediaType.APPLICATION_JSON_VALUE)
	public Mono<Map<String, Object>> getNodeInfo() {

		NodeInfo adminNodeInfo = chaindataService.getAdminNodeInfo();
		List<Peer> adminPeers = chaindataService.getAdminPeers();

		Map<String, Object> result = new HashMap<String, Object>();
		result.put("nodeInfo", adminNodeInfo);
		result.put("peers", adminPeers);

		return Mono.just(ok(result));

	}

}
